<?php
/*
template.php
Build $ 0.0.1 jul-16-2008 JD $
*/

include('includes/classes/template.class.php');

function template_header($override = false) {
	if ( ! $override === false && is_string($override) ) {
		$template_dir = $override;
	} else {
		$template_dir = J23_TEMPLATE;
	}
	$header_file = J23_PATH.'template/'.$template_dir.'/header.php';
	
	if ( ! file_exists($header_file) ) {
		$header_file = J23_PATH.'template/default/footer.php';
	}
	
	if ( ! file_exists($header_file) ) j23_die('CANNOT_OPEN_HEADER_FILE');
	
	$content = get_include_contents($header_file);
	echo $content;
}

function template_footer($override = false) {
	if ( ! $override === false && is_string($override) ) {
		$template_dir = $override;
	} else {
		$template_dir = J23_TEMPLATE;
	}
	$footer_file = J23_PATH.'template/'.$template_dir.'/footer.php';
	
	if ( ! file_exists($footer_file) ) {
		$footer_file = J23_PATH.'template/default/footer.php';
	}
	
	if ( ! file_exists($footer_file) ) j23_die('CANNOT_OPEN_FOOTER_FILE');
		
	$content = get_include_contents($footer_file);
	echo $content;
}

function template_file($file, $override = false) {
	if ( ! $override === false && is_string($override) ) {
		$template_dir = $override;
	} else {
		$template_dir = J23_TEMPLATE;
	}
	$template_file = J23_PATH.'template/'.$template_dir.'/'.$file.'.php';
	
	if ( ! file_exists($template_file) ) {
		$template_file = J23_PATH.'template/default/'.$file.'.php';
	}
	
	if ( ! file_exists($template_file) ) j23_die('CANNOT_OPEN_TEMPLATE_FILE');
	
	$content = get_include_contents($template_file);
	echo $content;
}

function custom_file($file, $override = false) {
	if ( ! $override === false && is_string($override) ) {
		$template_dir = $override;
	} else {
		$template_dir = J23_TEMPLATE;
	}

	$custom_file = J23_PATH.'template/'.$template_dir.'/'.$file.'.php';
	
	if ( ! file_exists($custom_file) ) j23_die('CANNOT_OPEN_CUSTOM_FILE');
	
	$content = get_include_contents($custom_file);
	echo $content;
}


// Start template file functions

function site_name($override = false) {
	echo lang_out('SITE_NAME', $override);
}

function site_description($override = false) {
	echo lang_out('SITE_DESCRIPTION', $override);
}
?>